package com.kgc.manger.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kgc.dao.TbContentCategoryMapper;
import com.kgc.dao.TbContentMapper;
import com.kgc.entity.TbContent;
import com.kgc.entity.TbContentExample;
import com.kgc.manger.service.ContentService;
import com.kgc.utils.ItripResult;
import com.kgc.utils.ResultTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ContentServiceImpl implements ContentService {
    @Autowired
    private TbContentMapper contentMapper;
    @Override
    public ResultTable findAll(int page, int limit) {
        PageHelper.startPage(page,limit);
        TbContentExample example=new TbContentExample();
        PageInfo<TbContent> pageInfo=new PageInfo(contentMapper.selectByExample(example));
        ResultTable resultTable=new ResultTable();
        resultTable.setCode(0);
        resultTable.setCount(pageInfo.getTotal());
        resultTable.setData(pageInfo.getList());
        resultTable.setMsg("ok");
        return resultTable;
    }

    @Override
    public ItripResult addContent(TbContent content) {
        contentMapper.insert(content);
        return ItripResult.ok();
    }
}
